package com.xbmzdx.fstj_app.controller;

import com.baomidou.mybatisplus.core.conditions.Condition;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xbmzdx.fstj_app.dao.BrandtableMapper;
import com.xbmzdx.fstj_app.pojo.Brandtable;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ljq
 * @since 2022-03-13
 */
@RestController
@RequestMapping("/brandtable")
public class BrandtableController {

    @Autowired
    private BrandtableMapper brandtableMapper;

    @ApiOperation(value = "插入品牌")
    @PostMapping("/insertBrand")
    public String insertBrand( @RequestBody Brandtable brandtable){
        int insert = brandtableMapper.insert (brandtable);
        if (insert==1){
            return "success";
        }
        return "0";
    }
    @ApiOperation(value = "查询")
    @PostMapping("/selectBrand")
    public List selectBrand(){
        List<Brandtable> brandtables = brandtableMapper.selectList (null);
        return brandtables;
    }

    @ApiOperation (value = "condition测试")
    @PostMapping("/selectedBrand")
    public List selectedBrand(String brandName){
        QueryWrapper<Brandtable> queryWrapper = new QueryWrapper<> ();
        queryWrapper.eq (brandName!=null,"brandName",brandName);
        List<Brandtable> brandtables = brandtableMapper.selectList (queryWrapper);
        return brandtables;

    }




    @ApiOperation(value = "查询")
    @PostMapping("/selectBrandMap")
    public List selectBrandMap(){
        Map map = new HashMap ();
        map.put ("isdelete",0);
        List<Brandtable> brandtables = brandtableMapper.selectByMap (map);
        return brandtables;
    }
    @ApiOperation(value = "删除")
    @PostMapping("/deleteBrand")
    public String deleteBrand(@RequestParam String id){
        Brandtable brandtable = brandtableMapper.selectById (id);
        int i = brandtableMapper.deleteById (brandtable);
        if (i==1){
            return "删除成功";
        }
        return "删除失败";
    }


    @ApiOperation(value = "更新")
    @PostMapping("/updateBrand")
    public String updateBrand(@RequestBody Brandtable brandtable){
        int update = brandtableMapper.updateById (brandtable);
        if (update==1){
            return "success";
        }
        return "0";
    }
}
